import math
class Solution(object):
    def mirrorReflection(self, p, q):
        t = p // math.gcd(p, q)
        if t % 2 == 1:
            m = t * q // p
            if m % 2 == 0:
                return 0
            else:
                return 1
        else:
            return 2

data = Solution()
p = 2
q = 1
print(data.mirrorReflection(p, q))
